<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>导航管理</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="${s.base}/js/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="${s.base}/css/base/base.css" media="all" />
</head>
<body class="childrenBody">
<form class="layui-form">
	<blockquote class="layui-elem-quote quoteBox">
		<form class="layui-form">
			<div class="layui-inline">
				<div class="layui-input-inline">
					<input type="text" class="layui-input" id="name" placeholder="请输入导航名称" />
				</div>
				<a class="layui-btn search_btn" data-type="reload">搜索</a>
			</div>
			<div class="layui-inline">
				<a class="layui-btn layui-btn-normal add_btn">添加</a>
			</div>
		</form>
	</blockquote>
	<table id="webNavigationList" lay-filter="webNavigationList"></table>

	<!--操作-->
	<script type="text/html" id="webNavigationBar">
		<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
		<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
		<a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="addChildBtn">添加</a>
	</script>
</form>
<script type="text/javascript" src="${s.base}/js/layui/layui.js"></script>
<script type="text/javascript" src="${s.base}/js/base/base.js"></script>
<script type="text/javascript">
    layui.use(['form','layer','laydate','table','laytpl'],function(){
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laydate = layui.laydate,
            laytpl = layui.laytpl,
            table = layui.table;

        //导航列表
        var tableIns = table.render({
            elem: '#webNavigationList',
            url : '/webNavigation/jsonList?useType=${useType}',
            cellMinWidth : 95,
            page : false,
            height : "full-125",
            limit : 200,
            method:'post',
            limits : [10,15,20,25],
            id : "webNavigationList",
            cols : [[
                {type: 'numbers', title: '序号'},
                {field: 'name', title: '导航名称', width:200, templet:function(row){
                    if(row.grade == "1"){
                        return row.name;
                    }else{
                        return "<div style=' margin-left: 40px;'>"+row.name+"</div>";
                    }
                }},
                {field: 'sign', title: '导航类型', align:'center',templet:function(row){
                    if(row.type == "1"){
                        return "目录";
                    }else{
                        return "菜单";
                    }
                }},
                {field: 'sort', title: '导航排序',  align:'center'},
                {field: 'url', title: '导航连接', align:'center'},
                {field: 'createTime', title: '创建时间', align:'center', minWidth:110, templet:function(d){
                    return timeStamp2String(d.createTime);
                }},
                {title: '操作',width:170, templet:'#webNavigationBar',align:"center"}
            ]]
        });

        //搜索
        $(".search_btn").on("click",function(){
            table.reload("webNavigationList",{
                page: false,
                where: {
                    name: $("#name").val()
                }
            })
        });

        //添加
        function addEntity(params){
            var title="二级导航添加";
            if(params==null||params==""){
                title="一级导航添加";
			}
            var index = layui.layer.open({
                title : title,
                type : 2,
                content : "/webNavigation/selectEntity"+params,
                success : function(layero, index){
                    var body = layui.layer.getChildFrame('body', index);
                    body.find(".closeLay").bind("click",function () {
                        layui.layer.close(index);
                    })
                    setTimeout(function(){
                        layui.layer.tips('点击此处返回导航列表', '.layui-layer-setwin .layui-layer-close', {
                            tips: 3
                        });
                    },500)
                }
            })
            layui.layer.full(index);
            //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
            $(window).on("resize",function(){
                layui.layer.full(index);
            })
        }
        $(".add_btn").click(function(){
            addEntity('?useType=${useType}');
        })

        //列表操作
        table.on('tool(webNavigationList)', function(obj){
            var layEvent = obj.event,
                data = obj.data;
            if(layEvent === 'edit'){ //编辑
                addEntity("?useType=${useType}&parentId="+data.parentId+"&id="+data.id);
            } else if(layEvent === 'del'){ //删除
                layer.confirm('是否删除名为【'+data.name+'】的导航？',{icon:3, title:'提示信息'},function(index){
                    $.get("/webNavigation/deleteEntity",{
                        "id":data.id,
                        "_method":"DELETE"
                    },function(result){
                        if(1==result.returnInfo.state){
                            tableIns.reload();
                            layer.close(index);
                        }else{
                            top.layer.msg(result.returnInfo.errorMsg);
                        }
                    })
                });
            } else if(layEvent === 'addChildBtn'){ //预览
                addEntity("?parentId="+data.id);
            }
        });

    })
</script>
</body>
</html>